package com.shupian.controller;

import com.shupian.constants.SystemConstants;
import com.shupian.domain.ResponseResult;
import com.shupian.domain.dto.AddCommentDTO;
import com.shupian.domain.entity.Comment;
import com.shupian.service.CommentService;
import com.shupian.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Min;

//评论相关
@Api(tags = "评论相关接口")
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 获取指定文章的评论列表
     * @param articleId 文章id
     * @param pageNum 页码
     * @param pageSize 每页条数
     * @return
     */
    @ApiOperation(value = "获取指定文章的评论列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页号",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小",required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "articleId",value = "文章id",required = true, dataType = "Long")
    })
    @GetMapping("/commentList")
    public ResponseResult CommentList(
            @Min(1) Long articleId,
            @Min(1) Integer pageNum,
            @Min(1) Integer pageSize){
        return commentService.CommentList(SystemConstants.ARTICLE_COMMENT,articleId,pageNum,pageSize);
    }
    @ApiOperation("添加评论")
    @PostMapping
    public ResponseResult addComment(@RequestBody @Valid AddCommentDTO addCommentDTO){
        Comment comment = BeanCopyUtils.copyBean(addCommentDTO, Comment.class);
        return commentService.addComment(comment);
    }

    @ApiOperation(value = "友链评论列表", notes = "获取一页友链评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页号"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小")
    })
    @GetMapping("linkCommentList")
    public ResponseResult linkCommentList(
            @Min(1) Integer pageNum,
            @Min(1) Integer pageSize){
        return commentService.CommentList(SystemConstants.LINK_COMMENT,null,pageNum,pageSize);
    }
}
